<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="${bao}.${mapperPackage}.${entity}Mapper">
    <resultMap id="PaperResult" type="java.util.HashMap">
    <#list sss as aa>
        <result property="${aa[0]}" column="${aa[1]}"/>
    </#list>
    </resultMap>

    <sql id="${entity?uncap_first}_s">
    <#list dataCol as field>
        ${field}<#if field_has_next>,</#if>
    </#list>
    </sql>

    <sql id="${entity?uncap_first}_p">
    <#list table.fields as field>
        <#noparse>#{</#noparse>${field.propertyName}<#noparse>}</#noparse><#if field_has_next>,</#if>
    </#list>
    </sql>

    <!--查询全部-->
    <select id="list" resultType="${bao}.${entityPackage}.${entity}" parameterType="${bao}.${entityPackage}.${entity}">
        select <include refid="${entity?uncap_first}_s"/> from ${table.name}
        <where>
    <#list sss as aa>
        <#if aa_index == 0>
        <#else>
            <if test="${aa[0]} != null and ${aa[0]} != ''">
                and ${aa[1]} like concat('%', <#noparse>#</#noparse>{${aa[0]}}, '%')
            </if>
        </#if>
    </#list>
        </where>
        <if test="orderBy != null and orderBy != ''">
            ORDER BY <#noparse>$</#noparse>{orderBy}
            <if test="descFlag != null and descFlag != ''">
                desc
            </if>
        </if>
    </select>

    <select id="get" resultType="${bao}.${entityPackage}.${entity}" parameterType="java.lang.String">
        select <include refid="${entity?uncap_first}_s"/> from ${table.name} where id = <#noparse>#</#noparse>{id}
    </select>


    <insert id="add${entity}" parameterType="${bao}.${entityPackage}.${entity}"  useGeneratedKeys="true" keyColumn="id" keyProperty="id">
        insert into ${table.name}(<include refid="${entity?uncap_first}_s"/>) VALUE(<include refid="${entity?uncap_first}_p"/>)
    </insert>

    <!--修改-->
    <update id="update${entity}" parameterType="${bao}.${entityPackage}.${entity}">
        update ${table.name} set
        <#list sss as aa>
        <#if aa_index == 0>
        <#else>
        <if test="${aa[0]} != null and ${aa[0]} != ''">
            ${aa[1]} = <#noparse>#</#noparse>{${aa[0]}}<#if aa_has_next>,</#if>
        </if>
        </#if>
        </#list>
        where id = <#noparse>#</#noparse>{id}
    </update>

    <!--删除-->
    <delete id="delete${entity}" parameterType="java.lang.String">
        delete from ${table.name} where id = <#noparse>#</#noparse>{id}
    </delete>

</mapper>
